<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>浏览器兼容</title>
</head>
<body>
   <div class="test"></div>
  <p class="test1"></p>
  <h1 class="test"></h1>

  <script>
   function getClassName(clsName){
    var allElement = document.body.getElementsByTagName('*');
    var arr = [];
    for(var i = 0; i < allElement.length; i++){
      if(allElement[i].getAttribute('class')){
        var clsArr = allElement[i].getAttribute('class').split(' ');
        console.log(clsArr);
        for(var o = 0; o < clsArr.length;o++){
          if(clsArr[o] == clsName){
            arr.push(allElement[i]);
            continue;
          }
        }
      }
    }
    return arr;
   }
   var cln = getClassName('test');
   console.log(cln);
  </script>
</body>

</html>